public class Test {
    public static void main(String[] args) {
        project project=new project();
        new Thread(()->{
            for (;;){
                project.add();
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        },"甲").start();
        new Thread(()->{
            for (;;){
                project.add();
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        },"乙").start();
        new Thread(()->{
            for (;;){
                project.add();
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        },"丙").start();
        new Thread(()->{
            for (;;){
                project.sub();
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        },"A").start();
        new Thread(()->{
            for (;;){
                project.sub();
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        },"B").start();
        new Thread(()->{
            for (;;){
                project.sub();
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        },"C").start();

    }
}
class project{
    int num=0;
    synchronized public void add()
    {
        while (num==1) {
            try {
                wait();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        num++;
        notifyAll();
        System.out.println(Thread.currentThread().getName()+"->"+num);

    }
    synchronized public void sub()
    {
        while (num==0) {
            try {
                wait();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        num--;
        notifyAll();
        System.out.println(Thread.currentThread().getName()+"->"+num);

    }
}
